﻿/*
 * Autore: Artur Tolstenco
 */

using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;

namespace RecipesManager.MainControls.GenericUserControls
{
    /// <summary>
    /// Interaction logic for LeftSideListUserControl.xaml
    /// </summary>
    public partial class LeftSideListUserControl
    {
        public IMyUserControls UsedBy
        {
            set 
            {
                if (value == null)
                    return;

                bt_add.Click += value.Bt_Add_Click;
                bt_delete.Click += value.Bt_Delete_Click;

                bt_back.Click += value.Bt_Back_Click;

                bt_clear_search.Click += value.Bt_Clear_Search_Click;
                bt_search.Click += value.Bt_Search_Click;

                lb_items.SelectionChanged += value.Lb_Items_SelectionChanged;

                label_section_title.Content = value.SectionName;

                if (label_section_title.Content.Equals(Application.Current.FindResource("IngredientsSectionLabel")))
                {
                    bt_add.ToolTip = Application.Current.FindResource("AddNewIngredientTooltip");
                    bt_delete.ToolTip = Application.Current.FindResource("DeleteSelectedIngredientTooltip");
                    bt_search.ToolTip = Application.Current.FindResource("SearchIngredientTooltip");
                }
                else if (label_section_title.Content.Equals(Application.Current.FindResource("CategoriesSectionLabel")))
                {
                    bt_add.ToolTip = Application.Current.FindResource("AddNewCategoryTooltip");
                    bt_delete.ToolTip = Application.Current.FindResource("DeleteSelectedCategoryTooltip");
                    bt_search.ToolTip = Application.Current.FindResource("SearchCategoryTooltip");
                }
                else if (label_section_title.Content.Equals(Application.Current.FindResource("ShopsSectionLabel")))
                {
                    bt_add.ToolTip = Application.Current.FindResource("AddNewShopTooltip");
                    bt_delete.ToolTip = Application.Current.FindResource("DeleteSelectedShopTooltip");
                    bt_search.ToolTip = Application.Current.FindResource("SearchShopTooltip");
                }
                else if (label_section_title.Content.Equals(Application.Current.FindResource("RecipesSectionLabel")))
                {
                    bt_add.ToolTip = Application.Current.FindResource("AddNewRecipeTooltip");
                    bt_delete.ToolTip = Application.Current.FindResource("DeleteSelectedRecipeTooltip");
                    bt_search.ToolTip = Application.Current.FindResource("SearchRecipeTooltip");
                }
                else if (label_section_title.Content.Equals(Application.Current.FindResource("EventsSectionLabel")))
                {
                    bt_add.ToolTip = Application.Current.FindResource("AddNewEventTooltip");
                    bt_delete.ToolTip = Application.Current.FindResource("DeleteSelectedEventTooltip");
                    bt_search.ToolTip = Application.Current.FindResource("SearchEventTooltip");
                }
                else if (label_section_title.Content.Equals(Application.Current.FindResource("GuestsSectionLabel")))
                {
                    bt_add.ToolTip = Application.Current.FindResource("AddNewGuestTooltip");
                    bt_delete.ToolTip = Application.Current.FindResource("DeleteSelectedGuestTooltip");
                    bt_search.ToolTip = Application.Current.FindResource("SearchGuestTooltip");
                }

                bt_clear_search.ToolTip = Application.Current.FindResource("ClearSearchButtonTooltip");

            }
        }

        public LeftSideListUserControl()
        {
            InitializeComponent();
            bt_delete.IsEnabled = false;
        }

        void Tb_search_OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
                bt_search.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

            }
        }
    }
}
